********************************************************************************
** 	TITLE:		de2021_gles_contact_networks                                  ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       ZA7700_v1-0-0	                                              **
**	DATE:		October 2022 					                              **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "de2021_gles_contact_networks", replace

* Open the dataset

use "ZA7700_v1-0-0.dta", clear


*****************************
** DISTRICT-LEVEL OUTCOMES **
*****************************

* Note: 1 = CDU/CSU, 4 = SPD, 5 = FDP, 6 = Green, 7 = Die Linke, 322 = AfD

gen district_outcome = .

replace district_outcome = 1 if wknr == 1
replace district_outcome = 1 if wknr == 2
replace district_outcome = 1 if wknr == 3
replace district_outcome = 1 if wknr == 4
replace district_outcome = 4 if wknr == 5
replace district_outcome = 1 if wknr == 6
replace district_outcome = 1 if wknr == 7
replace district_outcome = 1 if wknr == 8
replace district_outcome = 1 if wknr == 9
replace district_outcome = 1 if wknr == 10
replace district_outcome = 1 if wknr == 11
replace district_outcome = 1 if wknr == 12
replace district_outcome = 1 if wknr == 13
replace district_outcome = 1 if wknr == 14
replace district_outcome = 1 if wknr == 15
replace district_outcome = 1 if wknr == 16
replace district_outcome = 1 if wknr == 17
replace district_outcome = 4 if wknr == 18
replace district_outcome = 4 if wknr == 19
replace district_outcome = 4 if wknr == 20
replace district_outcome = 1 if wknr == 21
replace district_outcome = 4 if wknr == 22
replace district_outcome = 4 if wknr == 23
replace district_outcome = 4 if wknr == 24
replace district_outcome = 1 if wknr == 25
replace district_outcome = 4 if wknr == 26
replace district_outcome = 4 if wknr == 27
replace district_outcome = 1 if wknr == 28
replace district_outcome = 1 if wknr == 29
replace district_outcome = 1 if wknr == 30
replace district_outcome = 1 if wknr == 31
replace district_outcome = 1 if wknr == 32
replace district_outcome = 1 if wknr == 33
replace district_outcome = 1 if wknr == 34
replace district_outcome = 4 if wknr == 35
replace district_outcome = 1 if wknr == 36
replace district_outcome = 1 if wknr == 37
replace district_outcome = 1 if wknr == 38
replace district_outcome = 1 if wknr == 39
replace district_outcome = 1 if wknr == 40
replace district_outcome = 4 if wknr == 41
replace district_outcome = 4 if wknr == 42
replace district_outcome = 1 if wknr == 43
replace district_outcome = 1 if wknr == 44
replace district_outcome = 4 if wknr == 45
replace district_outcome = 4 if wknr == 46
replace district_outcome = 4 if wknr == 47
replace district_outcome = 4 if wknr == 48
replace district_outcome = 4 if wknr == 49
replace district_outcome = 4 if wknr == 50
replace district_outcome = 4 if wknr == 51
replace district_outcome = 1 if wknr == 52
replace district_outcome = 4 if wknr == 53
replace district_outcome = 4 if wknr == 54
replace district_outcome = 4 if wknr == 55
replace district_outcome = 1 if wknr == 56
replace district_outcome = 1 if wknr == 57
replace district_outcome = 1 if wknr == 58
replace district_outcome = 1 if wknr == 59
replace district_outcome = 1 if wknr == 60
replace district_outcome = 4 if wknr == 61
replace district_outcome = 1 if wknr == 62
replace district_outcome = 1 if wknr == 63
replace district_outcome = 1 if wknr == 64
replace district_outcome = 1 if wknr == 65
replace district_outcome = 1 if wknr == 66
replace district_outcome = 1 if wknr == 67
replace district_outcome = 1 if wknr == 68
replace district_outcome = 1 if wknr == 69
replace district_outcome = 1 if wknr == 70
replace district_outcome = 1 if wknr == 71
replace district_outcome = 1 if wknr == 72
replace district_outcome = 1 if wknr == 73
replace district_outcome = 1 if wknr == 74
replace district_outcome = 4 if wknr == 75
replace district_outcome = 7 if wknr == 76
replace district_outcome = 1 if wknr == 77
replace district_outcome = 4 if wknr == 78
replace district_outcome = 1 if wknr == 79
replace district_outcome = 1 if wknr == 80
replace district_outcome = 1 if wknr == 81
replace district_outcome = 4 if wknr == 82
replace district_outcome = 6 if wknr == 83
replace district_outcome = 7 if wknr == 84
replace district_outcome = 7 if wknr == 85
replace district_outcome = 7 if wknr == 86
replace district_outcome = 1 if wknr == 87
replace district_outcome = 4 if wknr == 88
replace district_outcome = 1 if wknr == 89
replace district_outcome = 1 if wknr == 90
replace district_outcome = 1 if wknr == 91
replace district_outcome = 1 if wknr == 92
replace district_outcome = 1 if wknr == 93
replace district_outcome = 1 if wknr == 94
replace district_outcome = 4 if wknr == 95
replace district_outcome = 4 if wknr == 96
replace district_outcome = 1 if wknr == 97
replace district_outcome = 1 if wknr == 98
replace district_outcome = 1 if wknr == 99
replace district_outcome = 1 if wknr == 100
replace district_outcome = 4 if wknr == 101
replace district_outcome = 4 if wknr == 102
replace district_outcome = 1 if wknr == 103
replace district_outcome = 1 if wknr == 104
replace district_outcome = 1 if wknr == 105
replace district_outcome = 1 if wknr == 106
replace district_outcome = 1 if wknr == 107
replace district_outcome = 1 if wknr == 108
replace district_outcome = 1 if wknr == 109
replace district_outcome = 1 if wknr == 110
replace district_outcome = 1 if wknr == 111
replace district_outcome = 1 if wknr == 112
replace district_outcome = 1 if wknr == 113
replace district_outcome = 1 if wknr == 114
replace district_outcome = 4 if wknr == 115
replace district_outcome = 4 if wknr == 116
replace district_outcome = 4 if wknr == 117
replace district_outcome = 4 if wknr == 118
replace district_outcome = 4 if wknr == 119
replace district_outcome = 1 if wknr == 120
replace district_outcome = 4 if wknr == 121
replace district_outcome = 4 if wknr == 122
replace district_outcome = 4 if wknr == 123
replace district_outcome = 1 if wknr == 124
replace district_outcome = 4 if wknr == 125
replace district_outcome = 1 if wknr == 126
replace district_outcome = 1 if wknr == 127
replace district_outcome = 1 if wknr == 128
replace district_outcome = 1 if wknr == 129
replace district_outcome = 1 if wknr == 130
replace district_outcome = 1 if wknr == 131
replace district_outcome = 4 if wknr == 132
replace district_outcome = 4 if wknr == 133
replace district_outcome = 4 if wknr == 134
replace district_outcome = 1 if wknr == 135
replace district_outcome = 1 if wknr == 136
replace district_outcome = 1 if wknr == 137
replace district_outcome = 4 if wknr == 138
replace district_outcome = 4 if wknr == 139
replace district_outcome = 4 if wknr == 140
replace district_outcome = 4 if wknr == 141
replace district_outcome = 4 if wknr == 142
replace district_outcome = 4 if wknr == 143
replace district_outcome = 4 if wknr == 144
replace district_outcome = 4 if wknr == 145
replace district_outcome = 1 if wknr == 146
replace district_outcome = 1 if wknr == 147
replace district_outcome = 1 if wknr == 148
replace district_outcome = 1 if wknr == 149
replace district_outcome = 4 if wknr == 150
replace district_outcome = 1 if wknr == 151
replace district_outcome = 1 if wknr == 152
replace district_outcome = 7 if wknr == 153
replace district_outcome = 1 if wknr == 154
replace district_outcome = 1 if wknr == 155
replace district_outcome = 322 if wknr == 156
replace district_outcome = 322 if wknr == 157
replace district_outcome = 322 if wknr == 158
replace district_outcome = 1 if wknr == 159
replace district_outcome = 1 if wknr == 160
replace district_outcome = 1 if wknr == 161
replace district_outcome = 1 if wknr == 162
replace district_outcome = 1 if wknr == 163
replace district_outcome = 1 if wknr == 164
replace district_outcome = 1 if wknr == 165
replace district_outcome = 1 if wknr == 166
replace district_outcome = 4 if wknr == 167
replace district_outcome = 4 if wknr == 168
replace district_outcome = 4 if wknr == 169
replace district_outcome = 4 if wknr == 170
replace district_outcome = 4 if wknr == 171
replace district_outcome = 1 if wknr == 172
replace district_outcome = 1 if wknr == 173
replace district_outcome = 1 if wknr == 174
replace district_outcome = 1 if wknr == 175
replace district_outcome = 1 if wknr == 176
replace district_outcome = 1 if wknr == 177
replace district_outcome = 1 if wknr == 178
replace district_outcome = 1 if wknr == 179
replace district_outcome = 1 if wknr == 180
replace district_outcome = 1 if wknr == 181
replace district_outcome = 1 if wknr == 182
replace district_outcome = 1 if wknr == 183
replace district_outcome = 1 if wknr == 184
replace district_outcome = 1 if wknr == 185
replace district_outcome = 1 if wknr == 186
replace district_outcome = 1 if wknr == 187
replace district_outcome = 1 if wknr == 188
replace district_outcome = 1 if wknr == 189
replace district_outcome = 1 if wknr == 190
replace district_outcome = 1 if wknr == 191
replace district_outcome = 1 if wknr == 192
replace district_outcome = 1 if wknr == 193
replace district_outcome = 1 if wknr == 194
replace district_outcome = 1 if wknr == 195
replace district_outcome = 1 if wknr == 196
replace district_outcome = 1 if wknr == 197
replace district_outcome = 1 if wknr == 198
replace district_outcome = 1 if wknr == 199
replace district_outcome = 1 if wknr == 200
replace district_outcome = 1 if wknr == 201
replace district_outcome = 1 if wknr == 202
replace district_outcome = 1 if wknr == 203
replace district_outcome = 1 if wknr == 204
replace district_outcome = 1 if wknr == 205
replace district_outcome = 1 if wknr == 206
replace district_outcome = 1 if wknr == 207
replace district_outcome = 1 if wknr == 208
replace district_outcome = 4 if wknr == 209
replace district_outcome = 1 if wknr == 210
replace district_outcome = 1 if wknr == 211
replace district_outcome = 1 if wknr == 212
replace district_outcome = 1 if wknr == 213
replace district_outcome = 1 if wknr == 214
replace district_outcome = 1 if wknr == 215
replace district_outcome = 1 if wknr == 216
replace district_outcome = 1 if wknr == 217
replace district_outcome = 1 if wknr == 218
replace district_outcome = 1 if wknr == 219
replace district_outcome = 1 if wknr == 220
replace district_outcome = 1 if wknr == 221
replace district_outcome = 1 if wknr == 222
replace district_outcome = 1 if wknr == 223
replace district_outcome = 1 if wknr == 224
replace district_outcome = 1 if wknr == 225
replace district_outcome = 1 if wknr == 226
replace district_outcome = 1 if wknr == 227
replace district_outcome = 1 if wknr == 228
replace district_outcome = 1 if wknr == 229
replace district_outcome = 1 if wknr == 230
replace district_outcome = 1 if wknr == 231
replace district_outcome = 1 if wknr == 232
replace district_outcome = 1 if wknr == 233
replace district_outcome = 1 if wknr == 234
replace district_outcome = 1 if wknr == 235
replace district_outcome = 1 if wknr == 236
replace district_outcome = 1 if wknr == 237
replace district_outcome = 1 if wknr == 238
replace district_outcome = 1 if wknr == 239
replace district_outcome = 1 if wknr == 240
replace district_outcome = 1 if wknr == 241
replace district_outcome = 1 if wknr == 242
replace district_outcome = 1 if wknr == 243
replace district_outcome = 1 if wknr == 244
replace district_outcome = 1 if wknr == 245
replace district_outcome = 1 if wknr == 246
replace district_outcome = 1 if wknr == 247
replace district_outcome = 1 if wknr == 248
replace district_outcome = 1 if wknr == 249
replace district_outcome = 1 if wknr == 250
replace district_outcome = 1 if wknr == 251
replace district_outcome = 1 if wknr == 252
replace district_outcome = 1 if wknr == 253
replace district_outcome = 1 if wknr == 254
replace district_outcome = 1 if wknr == 255
replace district_outcome = 1 if wknr == 256
replace district_outcome = 1 if wknr == 257
replace district_outcome = 1 if wknr == 258
replace district_outcome = 1 if wknr == 259
replace district_outcome = 1 if wknr == 260
replace district_outcome = 1 if wknr == 261
replace district_outcome = 1 if wknr == 262
replace district_outcome = 1 if wknr == 263
replace district_outcome = 1 if wknr == 264
replace district_outcome = 1 if wknr == 265
replace district_outcome = 1 if wknr == 266
replace district_outcome = 1 if wknr == 267
replace district_outcome = 1 if wknr == 268
replace district_outcome = 1 if wknr == 269
replace district_outcome = 1 if wknr == 270
replace district_outcome = 1 if wknr == 271
replace district_outcome = 1 if wknr == 272
replace district_outcome = 1 if wknr == 273
replace district_outcome = 1 if wknr == 274
replace district_outcome = 1 if wknr == 275
replace district_outcome = 1 if wknr == 276
replace district_outcome = 1 if wknr == 277
replace district_outcome = 1 if wknr == 278
replace district_outcome = 1 if wknr == 279
replace district_outcome = 1 if wknr == 280
replace district_outcome = 1 if wknr == 281
replace district_outcome = 1 if wknr == 282
replace district_outcome = 1 if wknr == 283
replace district_outcome = 1 if wknr == 284
replace district_outcome = 1 if wknr == 285
replace district_outcome = 1 if wknr == 286
replace district_outcome = 1 if wknr == 287
replace district_outcome = 1 if wknr == 288
replace district_outcome = 1 if wknr == 289
replace district_outcome = 1 if wknr == 290
replace district_outcome = 1 if wknr == 291
replace district_outcome = 1 if wknr == 292
replace district_outcome = 1 if wknr == 293
replace district_outcome = 1 if wknr == 294
replace district_outcome = 1 if wknr == 295
replace district_outcome = 4 if wknr == 296
replace district_outcome = 1 if wknr == 297
replace district_outcome = 1 if wknr == 298
replace district_outcome = 1 if wknr == 299


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by district

gen margin = .

replace margin = 4.765505 if wknr == 1
replace margin = 2.581741 if wknr == 2
replace margin = .0385246 if wknr == 3
replace margin = 1.111734 if wknr == 4
replace margin = 1.406187 if wknr == 5
replace margin = 3.506313 if wknr == 6
replace margin = 5.044483 if wknr == 7
replace margin = 4.094627 if wknr == 8
replace margin = 3.330957 if wknr == 9
replace margin = 4.464821 if wknr == 10
replace margin = 12.35727 if wknr == 11
replace margin = 8.74629 if wknr == 12
replace margin = 17.02789 if wknr == 13
replace margin = 8.721552 if wknr == 14
replace margin = 3.927704 if wknr == 15
replace margin = .5276508 if wknr == 16
replace margin = 9.537628 if wknr == 17
replace margin = 7.240822 if wknr == 18
replace margin = 1.077145 if wknr == 19
replace margin = .2243195 if wknr == 20
replace margin = 5.004261 if wknr == 21
replace margin = 19.45676 if wknr == 22
replace margin = 22.41182 if wknr == 23
replace margin = 35.09638 if wknr == 24
replace margin = 15.94445 if wknr == 25
replace margin = 23.39219 if wknr == 26
replace margin = 17.77889 if wknr == 27
replace margin = 11.71005 if wknr == 28
replace margin = 6.681368 if wknr == 29
replace margin = 2.858604 if wknr == 30
replace margin = 11.27931 if wknr == 31
replace margin = 28.37805 if wknr == 32
replace margin = 1.828943 if wknr == 33
replace margin = 1.138031 if wknr == 34
replace margin = 21.27072 if wknr == 35
replace margin = 1.907633 if wknr == 36
replace margin = 3.035521 if wknr == 37
replace margin = 6.525177 if wknr == 38
replace margin = 1.052589 if wknr == 39
replace margin = 4.377079 if wknr == 40
replace margin = 13.0697 if wknr == 41
replace margin = 6.419792 if wknr == 42
replace margin = 1.79763 if wknr == 43
replace margin = .5547943 if wknr == 44
replace margin = 19.29053 if wknr == 45
replace margin = 17.72585 if wknr == 46
replace margin = 15.24216 if wknr == 47
replace margin = 12.89115 if wknr == 48
replace margin = 11.4259 if wknr == 49
replace margin = 14.29134 if wknr == 50
replace margin = 15.48416 if wknr == 51
replace margin = 3.472305 if wknr == 52
replace margin = 5.284147 if wknr == 53
replace margin = 8.765158 if wknr == 54
replace margin = 16.85317 if wknr == 55
replace margin = 13.28567 if wknr == 56
replace margin = 9.356564 if wknr == 57
replace margin = 5.552097 if wknr == 58
replace margin = 1.327715 if wknr == 59
replace margin = 11.97284 if wknr == 60
replace margin = 15.26066 if wknr == 61
replace margin = 6.587542 if wknr == 62
replace margin = 6.528008 if wknr == 63
replace margin = 1.861303 if wknr == 64
replace margin = .3702984 if wknr == 65
replace margin = 5.73155 if wknr == 66
replace margin = 1.272947 if wknr == 67
replace margin = 2.244892 if wknr == 68
replace margin = 3.255802 if wknr == 69
replace margin = 14.81651 if wknr == 70
replace margin = .6778622 if wknr == 71
replace margin = 8.047813 if wknr == 72
replace margin = .2582607 if wknr == 73
replace margin = .1507568 if wknr == 74
replace margin = 7.854338 if wknr == 75
replace margin = 3.99218 if wknr == 76
replace margin = 1.423273 if wknr == 77
replace margin = 9.375835 if wknr == 78
replace margin = 3.14266 if wknr == 79
replace margin = 3.512867 if wknr == 80
replace margin = 1.957216 if wknr == 81
replace margin = 6.170858 if wknr == 82
replace margin = 20.20873 if wknr == 83
replace margin = 19.99437 if wknr == 84
replace margin = 7.558617 if wknr == 85
replace margin = 6.143686 if wknr == 86
replace margin = 4.592804 if wknr == 87
replace margin = 2.003117 if wknr == 88
replace margin = 13.80889 if wknr == 89
replace margin = 5.913597 if wknr == 90
replace margin = 2.475733 if wknr == 91
replace margin = 7.908987 if wknr == 92
replace margin = 3.991301 if wknr == 93
replace margin = 9.677277 if wknr == 94
replace margin = 1.653744 if wknr == 95
replace margin = .117321 if wknr == 96
replace margin = 4.055967 if wknr == 97
replace margin = 16.62103 if wknr == 98
replace margin = 7.126497 if wknr == 99
replace margin = 7.339508 if wknr == 100
replace margin = 25.18002 if wknr == 101
replace margin = 15.24924 if wknr == 102
replace margin = 4.984905 if wknr == 103
replace margin = 5.066626 if wknr == 104
replace margin = .6476498 if wknr == 105
replace margin = 8.739969 if wknr == 106
replace margin = 4.512024 if wknr == 107
replace margin = 3.770508 if wknr == 108
replace margin = 6.254543 if wknr == 109
replace margin = 7.941975 if wknr == 110
replace margin = 8.259253 if wknr == 111
replace margin = 9.181248 if wknr == 112
replace margin = 4.423084 if wknr == 113
replace margin = 6.768955 if wknr == 114
replace margin = 19.62398 if wknr == 115
replace margin = 19.3763 if wknr == 116
replace margin = 16.35642 if wknr == 117
replace margin = 12.36148 if wknr == 118
replace margin = 15.04348 if wknr == 119
replace margin = .6737061 if wknr == 120
replace margin = 15.42661 if wknr == 121
replace margin = 9.330959 if wknr == 122
replace margin = 20.71496 if wknr == 123
replace margin = 11.73596 if wknr == 124
replace margin = 12.02937 if wknr == 125
replace margin = 18.32392 if wknr == 126
replace margin = 15.79095 if wknr == 127
replace margin = 2.83589 if wknr == 128
replace margin = 6.17732 if wknr == 129
replace margin = 5.442764 if wknr == 130
replace margin = 14.20768 if wknr == 131
replace margin = 7.78075 if wknr == 132
replace margin = 9.724079 if wknr == 133
replace margin = 12.20267 if wknr == 134
replace margin = 4.521276 if wknr == 135
replace margin = 12.0996 if wknr == 136
replace margin = 28.92833 if wknr == 137
replace margin = 6.892384 if wknr == 138
replace margin = 10.80515 if wknr == 139
replace margin = 16.61965 if wknr == 140
replace margin = 23.67295 if wknr == 141
replace margin = 13.56421 if wknr == 142
replace margin = 18.7981 if wknr == 143
replace margin = 15.71194 if wknr == 144
replace margin = 14.07227 if wknr == 145
replace margin = 2.353916 if wknr == 146
replace margin = 8.206306 if wknr == 147
replace margin = 3.19911 if wknr == 148
replace margin = 7.506001 if wknr == 149
replace margin = 3.222658 if wknr == 150
replace margin = 4.945396 if wknr == 151
replace margin = .3124104 if wknr == 152
replace margin = 4.426081 if wknr == 153
replace margin = .1759853 if wknr == 154
replace margin = 8.668787 if wknr == 155
replace margin = 7.358641 if wknr == 156
replace margin = 9.727299 if wknr == 157
replace margin = 13.83 if wknr == 158
replace margin = 2.193905 if wknr == 159
replace margin = .0186405 if wknr == 160
replace margin = 9.666637 if wknr == 161
replace margin = 3.198185 if wknr == 162
replace margin = 5.268894 if wknr == 163
replace margin = 6.282955 if wknr == 164
replace margin = 4.361681 if wknr == 165
replace margin = .9200668 if wknr == 166
replace margin = 11.67659 if wknr == 167
replace margin = 15.66291 if wknr == 168
replace margin = 16.93738 if wknr == 169
replace margin = 15.33098 if wknr == 170
replace margin = 10.78114 if wknr == 171
replace margin = 2.967327 if wknr == 172
replace margin = .7704582 if wknr == 173
replace margin = 16.33316 if wknr == 174
replace margin = 2.996649 if wknr == 175
replace margin = 4.299574 if wknr == 176
replace margin = 1.322622 if wknr == 177
replace margin = 1.692553 if wknr == 178
replace margin = .4643154 if wknr == 179
replace margin = 3.302004 if wknr == 180
replace margin = 10.57613 if wknr == 181
replace margin = 7.275806 if wknr == 182
replace margin = 5.655924 if wknr == 183
replace margin = 5.704594 if wknr == 184
replace margin = 1.484707 if wknr == 185
replace margin = 3.583725 if wknr == 186
replace margin = 4.414341 if wknr == 187
replace margin = 3.306448 if wknr == 188
replace margin = 3.904518 if wknr == 189
replace margin = .9330692 if wknr == 190
replace margin = .7192078 if wknr == 191
replace margin = 2.961931 if wknr == 192
replace margin = 7.011938 if wknr == 193
replace margin = 6.80674 if wknr == 194
replace margin = 8.321276 if wknr == 195
replace margin = 11.28183 if wknr == 196
replace margin = 1.729902 if wknr == 197
replace margin = 4.062618 if wknr == 198
replace margin = 1.828478 if wknr == 199
replace margin = 7.399012 if wknr == 200
replace margin = 3.95809 if wknr == 201
replace margin = 10.36567 if wknr == 202
replace margin = 5.255341 if wknr == 203
replace margin = 1.461792 if wknr == 204
replace margin = 1.362494 if wknr == 205
replace margin = 1.875782 if wknr == 206
replace margin = 7.798336 if wknr == 207
replace margin = 2.104282 if wknr == 208
replace margin = 12.42229 if wknr == 209
replace margin = .3640785 if wknr == 210
replace margin = .0241699 if wknr == 211
replace margin = 31.94826 if wknr == 212
replace margin = 27.4011 if wknr == 213
replace margin = 22.69032 if wknr == 214
replace margin = 18.76209 if wknr == 215
replace margin = 30.98836 if wknr == 216
replace margin = 1.4513 if wknr == 217
replace margin = 9.734165 if wknr == 218
replace margin = .6954098 if wknr == 219
replace margin = .0694313 if wknr == 220
replace margin = 18.68356 if wknr == 221
replace margin = 22.35405 if wknr == 222
replace margin = 25.80895 if wknr == 223
replace margin = 18.24491 if wknr == 224
replace margin = 19.62619 if wknr == 225
replace margin = 27.45123 if wknr == 226
replace margin = 21.77752 if wknr == 227
replace margin = 24.70276 if wknr == 228
replace margin = 9.735016 if wknr == 229
replace margin = 18.37338 if wknr == 230
replace margin = 31.56695 if wknr == 231
replace margin = 24.30391 if wknr == 232
replace margin = 18.71004 if wknr == 233
replace margin = 12.26382 if wknr == 234
replace margin = 15.98034 if wknr == 235
replace margin = 17.99993 if wknr == 236
replace margin = 23.08501 if wknr == 237
replace margin = 10.43898 if wknr == 238
replace margin = 17.31469 if wknr == 239
replace margin = 31.56961 if wknr == 240
replace margin = 20.67761 if wknr == 241
replace margin = 14.36693 if wknr == 242
replace margin = 9.528194 if wknr == 243
replace margin = 5.884636 if wknr == 244
replace margin = 10.19599 if wknr == 245
replace margin = 21.07041 if wknr == 246
replace margin = 23.61995 if wknr == 247
replace margin = 20.06143 if wknr == 248
replace margin = 17.08646 if wknr == 249
replace margin = 22.24604 if wknr == 250
replace margin = 17.08737 if wknr == 251
replace margin = 7.506351 if wknr == 252
replace margin = 26.09128 if wknr == 253
replace margin = 21.91645 if wknr == 254
replace margin = 21.20064 if wknr == 255
replace margin = 13.96985 if wknr == 256
replace margin = 26.43551 if wknr == 257
replace margin = 16.5871 if wknr == 258
replace margin = 2.163607 if wknr == 259
replace margin = 8.596756 if wknr == 260
replace margin = 10.28469 if wknr == 261
replace margin = 9.052439 if wknr == 262
replace margin = 7.2638 if wknr == 263
replace margin = 6.263512 if wknr == 264
replace margin = 9.167191 if wknr == 265
replace margin = 7.857832 if wknr == 266
replace margin = 3.543697 if wknr == 267
replace margin = 12.46216 if wknr == 268
replace margin = 6.127361 if wknr == 269
replace margin = 15.17435 if wknr == 270
replace margin = 8.748049 if wknr == 271
replace margin = 7.598387 if wknr == 272
replace margin = 10.5088 if wknr == 273
replace margin = 6.061018 if wknr == 274
replace margin = 3.820801 if wknr == 275
replace margin = 15.16861 if wknr == 276
replace margin = 1.496422 if wknr == 277
replace margin = 7.742188 if wknr == 278
replace margin = 7.58824 if wknr == 279
replace margin = 16.56425 if wknr == 280
replace margin = 2.547157 if wknr == 281
replace margin = 3.488953 if wknr == 282
replace margin = .0540028 if wknr == 283
replace margin = 16.20658 if wknr == 284
replace margin = 14.71273 if wknr == 285
replace margin = 18.26622 if wknr == 286
replace margin = 13.99742 if wknr == 287
replace margin = 8.071058 if wknr == 288
replace margin = 14.68746 if wknr == 289
replace margin = 1.281731 if wknr == 290
replace margin = 13.97516 if wknr == 291
replace margin = 16.56263 if wknr == 292
replace margin = 9.595993 if wknr == 293
replace margin = 9.492943 if wknr == 294
replace margin = 11.83026 if wknr == 295
replace margin = 11.75017 if wknr == 296
replace margin = 8.764244 if wknr == 297
replace margin = 3.071251 if wknr == 298
replace margin = 10.47116 if wknr == 299

* Effective number of electoral parties by district

gen enep = .

replace enep = 5.098264 if wknr == 1
replace enep = 4.807517 if wknr == 2
replace enep = 4.676818 if wknr == 3
replace enep = 4.589927 if wknr == 4
replace enep = 4.746306 if wknr == 5
replace enep = 4.606751 if wknr == 6
replace enep = 4.723169 if wknr == 7
replace enep = 4.610062 if wknr == 8
replace enep = 4.20213 if wknr == 9
replace enep = 4.664075 if wknr == 10
replace enep = 4.527248 if wknr == 11
replace enep = 5.461548 if wknr == 12
replace enep = 4.827996 if wknr == 13
replace enep = 5.975488 if wknr == 14
replace enep = 5.872341 if wknr == 15
replace enep = 5.43724 if wknr == 16
replace enep = 4.808946 if wknr == 17
replace enep = 4.70399 if wknr == 18
replace enep = 4.64133 if wknr == 19
replace enep = 4.56353 if wknr == 20
replace enep = 4.37574 if wknr == 21
replace enep = 4.39942 if wknr == 22
replace enep = 4.422218 if wknr == 23
replace enep = 3.029742 if wknr == 24
replace enep = 3.358591 if wknr == 25
replace enep = 3.606839 if wknr == 26
replace enep = 4.19203 if wknr == 27
replace enep = 4.312635 if wknr == 28
replace enep = 4.004769 if wknr == 29
replace enep = 3.998192 if wknr == 30
replace enep = 3.605191 if wknr == 31
replace enep = 3.228162 if wknr == 32
replace enep = 4.024054 if wknr == 33
replace enep = 3.960654 if wknr == 34
replace enep = 3.196797 if wknr == 35
replace enep = 4.583936 if wknr == 36
replace enep = 4.643443 if wknr == 37
replace enep = 3.954666 if wknr == 38
replace enep = 4.180073 if wknr == 39
replace enep = 4.02438 if wknr == 40
replace enep = 4.429824 if wknr == 41
replace enep = 4.502894 if wknr == 42
replace enep = 4.103039 if wknr == 43
replace enep = 4.09613 if wknr == 44
replace enep = 3.654727 if wknr == 45
replace enep = 3.628438 if wknr == 46
replace enep = 3.89322 if wknr == 47
replace enep = 4.0287 if wknr == 48
replace enep = 3.998978 if wknr == 49
replace enep = 4.23854 if wknr == 50
replace enep = 3.677559 if wknr == 51
replace enep = 3.741176 if wknr == 52
replace enep = 4.12235 if wknr == 53
replace enep = 5.039545 if wknr == 54
replace enep = 4.640565 if wknr == 55
replace enep = 4.980084 if wknr == 56
replace enep = 5.509753 if wknr == 57
replace enep = 6.078244 if wknr == 58
replace enep = 5.696481 if wknr == 59
replace enep = 5.3115 if wknr == 60
replace enep = 5.174221 if wknr == 61
replace enep = 6.116335 if wknr == 62
replace enep = 5.727989 if wknr == 63
replace enep = 5.294751 if wknr == 64
replace enep = 5.747365 if wknr == 65
replace enep = 5.437622 if wknr == 66
replace enep = 5.263966 if wknr == 67
replace enep = 5.125992 if wknr == 68
replace enep = 6.211942 if wknr == 69
replace enep = 4.772394 if wknr == 70
replace enep = 5.339533 if wknr == 71
replace enep = 5.528586 if wknr == 72
replace enep = 4.86808 if wknr == 73
replace enep = 5.003626 if wknr == 74
replace enep = 5.256254 if wknr == 75
replace enep = 5.984523 if wknr == 76
replace enep = 5.498029 if wknr == 77
replace enep = 5.021702 if wknr == 78
replace enep = 4.918031 if wknr == 79
replace enep = 4.943717 if wknr == 80
replace enep = 5.061974 if wknr == 81
replace enep = 5.874126 if wknr == 82
replace enep = 4.632942 if wknr == 83
replace enep = 5.096787 if wknr == 84
replace enep = 5.307427 if wknr == 85
replace enep = 6.261743 if wknr == 86
replace enep = 4.480401 if wknr == 87
replace enep = 4.000666 if wknr == 88
replace enep = 4.019514 if wknr == 89
replace enep = 3.977322 if wknr == 90
replace enep = 4.277745 if wknr == 91
replace enep = 4.424753 if wknr == 92
replace enep = 5.002164 if wknr == 93
replace enep = 4.328996 if wknr == 94
replace enep = 4.647374 if wknr == 95
replace enep = 4.867123 if wknr == 96
replace enep = 4.507259 if wknr == 97
replace enep = 4.012422 if wknr == 98
replace enep = 4.518655 if wknr == 99
replace enep = 4.835933 if wknr == 100
replace enep = 3.644468 if wknr == 101
replace enep = 4.481089 if wknr == 102
replace enep = 4.579892 if wknr == 103
replace enep = 4.572443 if wknr == 104
replace enep = 4.387054 if wknr == 105
replace enep = 4.666697 if wknr == 106
replace enep = 4.834073 if wknr == 107
replace enep = 3.922607 if wknr == 108
replace enep = 4.084094 if wknr == 109
replace enep = 4.529672 if wknr == 110
replace enep = 4.223221 if wknr == 111
replace enep = 3.9474 if wknr == 112
replace enep = 4.242853 if wknr == 113
replace enep = 4.24356 if wknr == 114
replace enep = 4.123087 if wknr == 115
replace enep = 4.266414 if wknr == 116
replace enep = 4.336777 if wknr == 117
replace enep = 4.444668 if wknr == 118
replace enep = 4.358705 if wknr == 119
replace enep = 4.351722 if wknr == 120
replace enep = 3.853086 if wknr == 121
replace enep = 4.034875 if wknr == 122
replace enep = 4.155163 if wknr == 123
replace enep = 3.745475 if wknr == 124
replace enep = 3.967033 if wknr == 125
replace enep = 3.557486 if wknr == 126
replace enep = 3.733531 if wknr == 127
replace enep = 4.060031 if wknr == 128
replace enep = 4.20439 if wknr == 129
replace enep = 3.935895 if wknr == 130
replace enep = 3.932535 if wknr == 131
replace enep = 4.898795 if wknr == 132
replace enep = 4.291979 if wknr == 133
replace enep = 4.119772 if wknr == 134
replace enep = 4.811632 if wknr == 135
replace enep = 3.826212 if wknr == 136
replace enep = 3.426826 if wknr == 137
replace enep = 4.624743 if wknr == 138
replace enep = 4.434907 if wknr == 139
replace enep = 4.153648 if wknr == 140
replace enep = 3.879972 if wknr == 141
replace enep = 5.356887 if wknr == 142
replace enep = 4.34892 if wknr == 143
replace enep = 3.844232 if wknr == 144
replace enep = 3.835047 if wknr == 145
replace enep = 4.20707 if wknr == 146
replace enep = 3.532063 if wknr == 147
replace enep = 4.301107 if wknr == 148
replace enep = 3.967263 if wknr == 149
replace enep = 4.300036 if wknr == 150
replace enep = 5.443359 if wknr == 151
replace enep = 6.525357 if wknr == 152
replace enep = 6.265166 if wknr == 153
replace enep = 5.561421 if wknr == 154
replace enep = 5.294136 if wknr == 155
replace enep = 4.673115 if wknr == 156
replace enep = 4.410237 if wknr == 157
replace enep = 5.419931 if wknr == 158
replace enep = 6.368723 if wknr == 159
replace enep = 7.20644 if wknr == 160
replace enep = 4.582809 if wknr == 161
replace enep = 5.792436 if wknr == 162
replace enep = 5.3257 if wknr == 163
replace enep = 4.929907 if wknr == 164
replace enep = 5.700406 if wknr == 165
replace enep = 4.876704 if wknr == 166
replace enep = 4.143528 if wknr == 167
replace enep = 4.611044 if wknr == 168
replace enep = 3.531162 if wknr == 169
replace enep = 4.158413 if wknr == 170
replace enep = 4.221088 if wknr == 171
replace enep = 4.39607 if wknr == 172
replace enep = 4.67311 if wknr == 173
replace enep = 4.311564 if wknr == 174
replace enep = 4.767618 if wknr == 175
replace enep = 4.672917 if wknr == 176
replace enep = 4.793245 if wknr == 177
replace enep = 4.6951 if wknr == 178
replace enep = 5.233429 if wknr == 179
replace enep = 4.698456 if wknr == 180
replace enep = 4.660533 if wknr == 181
replace enep = 5.238721 if wknr == 182
replace enep = 4.796093 if wknr == 183
replace enep = 4.555765 if wknr == 184
replace enep = 5.169153 if wknr == 185
replace enep = 5.040977 if wknr == 186
replace enep = 4.6194 if wknr == 187
replace enep = 4.796335 if wknr == 188
replace enep = 5.233249 if wknr == 189
replace enep = 5.265283 if wknr == 190
replace enep = 6.363508 if wknr == 191
replace enep = 5.539649 if wknr == 192
replace enep = 6.088085 if wknr == 193
replace enep = 5.082258 if wknr == 194
replace enep = 5.322134 if wknr == 195
replace enep = 4.538428 if wknr == 196
replace enep = 4.517767 if wknr == 197
replace enep = 4.244431 if wknr == 198
replace enep = 4.569495 if wknr == 199
replace enep = 4.478782 if wknr == 200
replace enep = 4.58805 if wknr == 201
replace enep = 4.154561 if wknr == 202
replace enep = 4.658856 if wknr == 203
replace enep = 4.608108 if wknr == 204
replace enep = 5.652382 if wknr == 205
replace enep = 4.478018 if wknr == 206
replace enep = 4.817512 if wknr == 207
replace enep = 4.854821 if wknr == 208
replace enep = 5.112842 if wknr == 209
replace enep = 4.712007 if wknr == 210
replace enep = 5.138664 if wknr == 211
replace enep = 4.207487 if wknr == 212
replace enep = 4.186173 if wknr == 213
replace enep = 5.131808 if wknr == 214
replace enep = 4.614715 if wknr == 215
replace enep = 3.977318 if wknr == 216
replace enep = 5.285904 if wknr == 217
replace enep = 4.990325 if wknr == 218
replace enep = 5.010582 if wknr == 219
replace enep = 5.036777 if wknr == 220
replace enep = 4.328462 if wknr == 221
replace enep = 5.243592 if wknr == 222
replace enep = 4.348375 if wknr == 223
replace enep = 4.56374 if wknr == 224
replace enep = 4.984855 if wknr == 225
replace enep = 4.398387 if wknr == 226
replace enep = 4.690844 if wknr == 227
replace enep = 5.1399 if wknr == 228
replace enep = 5.450303 if wknr == 229
replace enep = 5.134568 if wknr == 230
replace enep = 4.025533 if wknr == 231
replace enep = 4.451551 if wknr == 232
replace enep = 5.066273 if wknr == 233
replace enep = 4.506568 if wknr == 234
replace enep = 4.432651 if wknr == 235
replace enep = 4.675164 if wknr == 236
replace enep = 4.06281 if wknr == 237
replace enep = 4.402661 if wknr == 238
replace enep = 3.969767 if wknr == 239
replace enep = 3.572968 if wknr == 240
replace enep = 4.669326 if wknr == 241
replace enep = 4.622963 if wknr == 242
replace enep = 4.880479 if wknr == 243
replace enep = 5.166008 if wknr == 244
replace enep = 4.736198 if wknr == 245
replace enep = 4.751144 if wknr == 246
replace enep = 4.32734 if wknr == 247
replace enep = 4.525754 if wknr == 248
replace enep = 4.412371 if wknr == 249
replace enep = 4.315106 if wknr == 250
replace enep = 4.461104 if wknr == 251
replace enep = 5.765568 if wknr == 252
replace enep = 4.419132 if wknr == 253
replace enep = 4.257411 if wknr == 254
replace enep = 4.914879 if wknr == 255
replace enep = 5.85906 if wknr == 256
replace enep = 4.833897 if wknr == 257
replace enep = 4.077371 if wknr == 258
replace enep = 5.374012 if wknr == 259
replace enep = 5.188084 if wknr == 260
replace enep = 4.879123 if wknr == 261
replace enep = 5.130398 if wknr == 262
replace enep = 5.056234 if wknr == 263
replace enep = 5.215534 if wknr == 264
replace enep = 5.245733 if wknr == 265
replace enep = 5.143247 if wknr == 266
replace enep = 5.295764 if wknr == 267
replace enep = 5.153188 if wknr == 268
replace enep = 5.100969 if wknr == 269
replace enep = 4.525219 if wknr == 270
replace enep = 5.230855 if wknr == 271
replace enep = 5.11445 if wknr == 272
replace enep = 4.864035 if wknr == 273
replace enep = 4.905345 if wknr == 274
replace enep = 5.445702 if wknr == 275
replace enep = 4.757379 if wknr == 276
replace enep = 4.951284 if wknr == 277
replace enep = 5.360254 if wknr == 278
replace enep = 5.582511 if wknr == 279
replace enep = 5.073457 if wknr == 280
replace enep = 4.851119 if wknr == 281
replace enep = 5.486754 if wknr == 282
replace enep = 5.150154 if wknr == 283
replace enep = 4.997364 if wknr == 284
replace enep = 5.266557 if wknr == 285
replace enep = 4.702682 if wknr == 286
replace enep = 4.748695 if wknr == 287
replace enep = 4.60923 if wknr == 288
replace enep = 5.100708 if wknr == 289
replace enep = 5.272107 if wknr == 290
replace enep = 5.03881 if wknr == 291
replace enep = 5.019271 if wknr == 292
replace enep = 5.237272 if wknr == 293
replace enep = 5.35188 if wknr == 294
replace enep = 5.355641 if wknr == 295
replace enep = 4.453236 if wknr == 296
replace enep = 4.247168 if wknr == 297
replace enep = 4.067963 if wknr == 298
replace enep = 4.38077 if wknr == 299


*******************************
** INCUMBENT PARTY REELECTED **
*******************************

gen reelected = .

replace reelected = 0 if wknr == 1
replace reelected = 1 if wknr == 2
replace reelected = 1 if wknr == 3
replace reelected = 0 if wknr == 4
replace reelected = 1 if wknr == 5
replace reelected = 0 if wknr == 6
replace reelected = 0 if wknr == 7
replace reelected = 0 if wknr == 8
replace reelected = 0 if wknr == 9
replace reelected = 0 if wknr == 10
replace reelected = 0 if wknr == 11
replace reelected = 0 if wknr == 12
replace reelected = 0 if wknr == 13
replace reelected = 0 if wknr == 14
replace reelected = 0 if wknr == 15
replace reelected = 0 if wknr == 16
replace reelected = 0 if wknr == 17
replace reelected = 1 if wknr == 18
replace reelected = 0 if wknr == 19
replace reelected = 0 if wknr == 20
replace reelected = 0 if wknr == 21
replace reelected = 1 if wknr == 22
replace reelected = 1 if wknr == 23
replace reelected = 1 if wknr == 24
replace reelected = 1 if wknr == 25
replace reelected = 1 if wknr == 26
replace reelected = 1 if wknr == 27
replace reelected = 0 if wknr == 28
replace reelected = 0 if wknr == 29
replace reelected = 1 if wknr == 30
replace reelected = 1 if wknr == 31
replace reelected = 1 if wknr == 32
replace reelected = 1 if wknr == 33
replace reelected = 1 if wknr == 34
replace reelected = 1 if wknr == 35
replace reelected = 0 if wknr == 36
replace reelected = 0 if wknr == 37
replace reelected = 1 if wknr == 38
replace reelected = 0 if wknr == 39
replace reelected = 0 if wknr == 40
replace reelected = 1 if wknr == 41
replace reelected = 1 if wknr == 42
replace reelected = 0 if wknr == 43
replace reelected = 1 if wknr == 44
replace reelected = 1 if wknr == 45
replace reelected = 1 if wknr == 46
replace reelected = 1 if wknr == 47
replace reelected = 1 if wknr == 48
replace reelected = 1 if wknr == 49
replace reelected = 1 if wknr == 50
replace reelected = 1 if wknr == 51
replace reelected = 0 if wknr == 52
replace reelected = 1 if wknr == 53
replace reelected = 1 if wknr == 54
replace reelected = 1 if wknr == 55
replace reelected = 0 if wknr == 56
replace reelected = 0 if wknr == 57
replace reelected = 0 if wknr == 58
replace reelected = 0 if wknr == 59
replace reelected = 0 if wknr == 60
replace reelected = 1 if wknr == 61
replace reelected = 0 if wknr == 62
replace reelected = 0 if wknr == 63
replace reelected = 0 if wknr == 64
replace reelected = 0 if wknr == 65
replace reelected = 0 if wknr == 66
replace reelected = 0 if wknr == 67
replace reelected = 1 if wknr == 68
replace reelected = 0 if wknr == 69
replace reelected = 1 if wknr == 70
replace reelected = 0 if wknr == 71
replace reelected = 0 if wknr == 72
replace reelected = 1 if wknr == 73
replace reelected = 0 if wknr == 74
replace reelected = 0 if wknr == 75
replace reelected = 0 if wknr == 76
replace reelected = 1 if wknr == 77
replace reelected = 1 if wknr == 78
replace reelected = 1 if wknr == 79
replace reelected = 0 if wknr == 80
replace reelected = 0 if wknr == 81
replace reelected = 1 if wknr == 82
replace reelected = 1 if wknr == 83
replace reelected = 1 if wknr == 84
replace reelected = 0 if wknr == 85
replace reelected = 1 if wknr == 86
replace reelected = 0 if wknr == 87
replace reelected = 1 if wknr == 88
replace reelected = 1 if wknr == 89
replace reelected = 1 if wknr == 90
replace reelected = 1 if wknr == 91
replace reelected = 1 if wknr == 92
replace reelected = 0 if wknr == 93
replace reelected = 0 if wknr == 94
replace reelected = 1 if wknr == 95
replace reelected = 0 if wknr == 96
replace reelected = 1 if wknr == 97
replace reelected = 1 if wknr == 98
replace reelected = 1 if wknr == 99
replace reelected = 1 if wknr == 100
replace reelected = 1 if wknr == 101
replace reelected = 1 if wknr == 102
replace reelected = 0 if wknr == 103
replace reelected = 1 if wknr == 104
replace reelected = 1 if wknr == 105
replace reelected = 1 if wknr == 106
replace reelected = 0 if wknr == 107
replace reelected = 1 if wknr == 108
replace reelected = 1 if wknr == 109
replace reelected = 1 if wknr == 110
replace reelected = 1 if wknr == 111
replace reelected = 1 if wknr == 112
replace reelected = 0 if wknr == 113
replace reelected = 0 if wknr == 114
replace reelected = 1 if wknr == 115
replace reelected = 1 if wknr == 116
replace reelected = 1 if wknr == 117
replace reelected = 1 if wknr == 118
replace reelected = 1 if wknr == 119
replace reelected = 1 if wknr == 120
replace reelected = 1 if wknr == 121
replace reelected = 1 if wknr == 122
replace reelected = 1 if wknr == 123
replace reelected = 1 if wknr == 124
replace reelected = 1 if wknr == 125
replace reelected = 1 if wknr == 126
replace reelected = 1 if wknr == 127
replace reelected = 1 if wknr == 128
replace reelected = 0 if wknr == 129
replace reelected = 1 if wknr == 130
replace reelected = 1 if wknr == 131
replace reelected = 1 if wknr == 132
replace reelected = 1 if wknr == 133
replace reelected = 1 if wknr == 134
replace reelected = 0 if wknr == 135
replace reelected = 1 if wknr == 136
replace reelected = 1 if wknr == 137
replace reelected = 1 if wknr == 138
replace reelected = 1 if wknr == 139
replace reelected = 1 if wknr == 140
replace reelected = 1 if wknr == 141
replace reelected = 1 if wknr == 142
replace reelected = 1 if wknr == 143
replace reelected = 1 if wknr == 144
replace reelected = 1 if wknr == 145
replace reelected = 1 if wknr == 146
replace reelected = 1 if wknr == 147
replace reelected = 1 if wknr == 148
replace reelected = 1 if wknr == 149
replace reelected = 0 if wknr == 150
replace reelected = 0 if wknr == 151
replace reelected = 1 if wknr == 152
replace reelected = 1 if wknr == 153
replace reelected = 0 if wknr == 154
replace reelected = 0 if wknr == 155
replace reelected = 1 if wknr == 156
replace reelected = 1 if wknr == 157
replace reelected = 1 if wknr == 158
replace reelected = 1 if wknr == 159
replace reelected = 1 if wknr == 160
replace reelected = 0 if wknr == 161
replace reelected = 0 if wknr == 162
replace reelected = 0 if wknr == 163
replace reelected = 0 if wknr == 164
replace reelected = 0 if wknr == 165
replace reelected = 1 if wknr == 166
replace reelected = 1 if wknr == 167
replace reelected = 1 if wknr == 168
replace reelected = 1 if wknr == 169
replace reelected = 1 if wknr == 170
replace reelected = 1 if wknr == 171
replace reelected = 0 if wknr == 172
replace reelected = 0 if wknr == 173
replace reelected = 1 if wknr == 174
replace reelected = 0 if wknr == 175
replace reelected = 1 if wknr == 176
replace reelected = 0 if wknr == 177
replace reelected = 1 if wknr == 178
replace reelected = 1 if wknr == 179
replace reelected = 0 if wknr == 180
replace reelected = 1 if wknr == 181
replace reelected = 0 if wknr == 182
replace reelected = 0 if wknr == 183
replace reelected = 0 if wknr == 184
replace reelected = 1 if wknr == 185
replace reelected = 0 if wknr == 186
replace reelected = 0 if wknr == 187
replace reelected = 1 if wknr == 188
replace reelected = 1 if wknr == 189
replace reelected = 0 if wknr == 190
replace reelected = 0 if wknr == 191
replace reelected = 0 if wknr == 192
replace reelected = 0 if wknr == 193
replace reelected = 0 if wknr == 194
replace reelected = 0 if wknr == 195
replace reelected = 0 if wknr == 196
replace reelected = 1 if wknr == 197
replace reelected = 1 if wknr == 198
replace reelected = 1 if wknr == 199
replace reelected = 1 if wknr == 200
replace reelected = 0 if wknr == 201
replace reelected = 1 if wknr == 202
replace reelected = 0 if wknr == 203
replace reelected = 0 if wknr == 204
replace reelected = 0 if wknr == 205
replace reelected = 1 if wknr == 206
replace reelected = 0 if wknr == 207
replace reelected = 1 if wknr == 208
replace reelected = 1 if wknr == 209
replace reelected = 0 if wknr == 210
replace reelected = 0 if wknr == 211
replace reelected = 1 if wknr == 212
replace reelected = 1 if wknr == 213
replace reelected = 1 if wknr == 214
replace reelected = 1 if wknr == 215
replace reelected = 1 if wknr == 216
replace reelected = 1 if wknr == 217
replace reelected = 1 if wknr == 218
replace reelected = 0 if wknr == 219
replace reelected = 1 if wknr == 220
replace reelected = 1 if wknr == 221
replace reelected = 1 if wknr == 222
replace reelected = 1 if wknr == 223
replace reelected = 1 if wknr == 224
replace reelected = 1 if wknr == 225
replace reelected = 1 if wknr == 226
replace reelected = 1 if wknr == 227
replace reelected = 1 if wknr == 228
replace reelected = 1 if wknr == 229
replace reelected = 1 if wknr == 230
replace reelected = 1 if wknr == 231
replace reelected = 1 if wknr == 232
replace reelected = 1 if wknr == 233
replace reelected = 1 if wknr == 234
replace reelected = 1 if wknr == 235
replace reelected = 1 if wknr == 236
replace reelected = 1 if wknr == 237
replace reelected = 1 if wknr == 238
replace reelected = 1 if wknr == 239
replace reelected = 1 if wknr == 240
replace reelected = 1 if wknr == 241
replace reelected = 1 if wknr == 242
replace reelected = 1 if wknr == 243
replace reelected = 1 if wknr == 244
replace reelected = 1 if wknr == 245
replace reelected = 1 if wknr == 246
replace reelected = 1 if wknr == 247
replace reelected = 1 if wknr == 248
replace reelected = 1 if wknr == 249
replace reelected = 1 if wknr == 250
replace reelected = 1 if wknr == 251
replace reelected = 1 if wknr == 252
replace reelected = 1 if wknr == 253
replace reelected = 1 if wknr == 254
replace reelected = 1 if wknr == 255
replace reelected = 1 if wknr == 256
replace reelected = 1 if wknr == 257
replace reelected = 0 if wknr == 258
replace reelected = 1 if wknr == 259
replace reelected = 1 if wknr == 260
replace reelected = 1 if wknr == 261
replace reelected = 1 if wknr == 262
replace reelected = 1 if wknr == 263
replace reelected = 1 if wknr == 264
replace reelected = 1 if wknr == 265
replace reelected = 1 if wknr == 266
replace reelected = 1 if wknr == 267
replace reelected = 1 if wknr == 268
replace reelected = 1 if wknr == 269
replace reelected = 1 if wknr == 270
replace reelected = 0 if wknr == 271
replace reelected = 1 if wknr == 272
replace reelected = 1 if wknr == 273
replace reelected = 0 if wknr == 274
replace reelected = 0 if wknr == 275
replace reelected = 1 if wknr == 276
replace reelected = 1 if wknr == 277
replace reelected = 1 if wknr == 278
replace reelected = 1 if wknr == 279
replace reelected = 1 if wknr == 280
replace reelected = 0 if wknr == 281
replace reelected = 1 if wknr == 282
replace reelected = 1 if wknr == 283
replace reelected = 1 if wknr == 284
replace reelected = 1 if wknr == 285
replace reelected = 1 if wknr == 286
replace reelected = 1 if wknr == 287
replace reelected = 1 if wknr == 288
replace reelected = 1 if wknr == 289
replace reelected = 1 if wknr == 290
replace reelected = 1 if wknr == 291
replace reelected = 1 if wknr == 292
replace reelected = 1 if wknr == 293
replace reelected = 1 if wknr == 294
replace reelected = 1 if wknr == 295
replace reelected = 1 if wknr == 296
replace reelected = 0 if wknr == 297
replace reelected = 0 if wknr == 298
replace reelected = 0 if wknr == 299


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate = intdate

format %tdMon_DD,_CCYY surveydate

gen edate = 20210926

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Gender

gen male = d1

recode male (2=0)

recode male (-99=.)

* Age

gen birthyear = d2a

replace birthyear = "-99" if birthyear == "-99 keine Angabe"
replace birthyear = "1931" if birthyear == "1931 oder frueher"

destring birthyear, generate(age)

recode age (-99=.)

replace age = 2021 - age

replace age = . if age < 17

* Education

gen education = d7

recode education (-99=.)
recode education (-93=.)
recode education (-73=.)

* Interest for election

gen interest = q2

recode interest (-99=.)
recode interest (-73=.)

replace interest = 6 - interest

* Caring about outcome

gen care_whole = q3

recode care_whole (-99=.)
recode care_whole (-73=.)

replace care_whole = 6 - care_whole

* Party identification (national) 

gen pid1 = q75a
gen pid2 = q75b

recode pid1 (2=1)
recode pid1 (3=1) // CDU and CSU recoded as CDU/CSU 

recode pid2 (2=1)
recode pid2 (3=1) // CDU and CSU recoded as CDU/CSU 

gen pid = max(pid1,pid2)

gen pidstatus_whole = .

replace pidstatus_whole = 9999 if pid == .
replace pidstatus_whole = 9999 if pid == -99
replace pidstatus_whole = 9999 if pid == -93
replace pidstatus_whole = 9999 if pid == -73

replace pidstatus_whole = 2 if pid == 808

replace pidstatus_whole = 3 if pid == 4 & pidstatus_whole!=2 & pidstatus_whole!=9999 | pid == 5 & pidstatus_whole!=2 & pidstatus_whole!=9999 | pid == 6 & pidstatus_whole!=2 & pidstatus_whole!=9999

replace pidstatus_whole = 1 if pid!=4 & pid!=5 & pid!=6 & pid!=. & pidstatus_whole!=2 & pidstatus_whole!=3 & pidstatus_whole!=9999

replace pidstatus_whole = . if pidstatus_whole == 9999

label define pidstatus 1 "Loser PID" 2 "No PID" 3 "Winner PID"
label values pidstatus_whole pidstatus

* Party identification scale (national)

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & q76 == 1
replace pidscale_whole = 2 if pidstatus_whole == 1 & q76 == 2
replace pidscale_whole = 3 if pidstatus_whole == 1 & q76 == 3
replace pidscale_whole = 4 if pidstatus_whole == 1 & q76 == 4
replace pidscale_whole = 5 if pidstatus_whole == 1 & q76 == 5
replace pidscale_whole = 6 if pidstatus_whole == 2
replace pidscale_whole = 7 if pidstatus_whole == 3 & q76 == 5
replace pidscale_whole = 8 if pidstatus_whole == 3 & q76 == 4
replace pidscale_whole = 9 if pidstatus_whole == 3 & q76 == 3
replace pidscale_whole = 10 if pidstatus_whole == 3 & q76 == 2
replace pidscale_whole = 11 if pidstatus_whole == 3 & q76 == 1

label define pidscale 1 "Very strong loser PID" 2 "Fairly strong loser PID" 3 "Moderate loser PID" 4 "Fairly weak loser PID" 5 "Very weak loser PID" 6 "No PID" 7 "Very weak winner PID" 8 "Fairly weak winner PID" 9 "Moderate winner PID" 10 "Fairly strong winner PID" 11 "Very strong winner PID"
label values pidscale_whole pidscale

* Party identification (district)

gen pidstatus_district = .

replace pidstatus_district = 9999 if pid == .
replace pidstatus_district = 9999 if pid == -99
replace pidstatus_district = 9999 if pid == -93
replace pidstatus_district = 9999 if pid == -73

replace pidstatus_district = 2 if pid == 808

replace pidstatus_district = 3 if pid == district_outcome & pidstatus_district!=2 & pidstatus_district!=9999

replace pidstatus_district = 1 if pid!=district_outcome & pid!=. & pidstatus_district!=2 & pidstatus_district!=3 & pidstatus_district!=9999

replace pidstatus_district = . if pidstatus_district == 9999

label values pidstatus_district pidstatus

* Party identification scale (district)

gen pidscale_district = .

replace pidscale_district = 1 if pidstatus_district == 1 & q76 == 1
replace pidscale_district = 2 if pidstatus_district == 1 & q76 == 2
replace pidscale_district = 3 if pidstatus_district == 1 & q76 == 3
replace pidscale_district = 4 if pidstatus_district == 1 & q76 == 4
replace pidscale_district = 5 if pidstatus_district == 1 & q76 == 5
replace pidscale_district = 6 if pidstatus_district == 2
replace pidscale_district = 7 if pidstatus_district == 3 & q76 == 5
replace pidscale_district = 8 if pidstatus_district == 3 & q76 == 4
replace pidscale_district = 9 if pidstatus_district == 3 & q76 == 3
replace pidscale_district = 10 if pidstatus_district == 3 & q76 == 2
replace pidscale_district = 11 if pidstatus_district == 3 & q76 == 1

label values pidscale_district pidscale

* Coalition preference

gen coalprefA = q57a
gen coalprefB = q57b
gen coalprefC = q57c
gen coalprefD = q57d
gen coalprefE = q57e
gen coalprefF = q57f
gen coalprefG = q57g
gen coalprefH = q57h
gen coalprefI = q57i

recode coalprefA coalprefB coalprefC coalprefD coalprefE coalprefF coalprefG coalprefH coalprefI (-73=.)
recode coalprefA coalprefB coalprefC coalprefD coalprefE coalprefF coalprefG coalprefH coalprefI (-93=.)
recode coalprefA coalprefB coalprefC coalprefD coalprefE coalprefF coalprefG coalprefH coalprefI (-98=.)
recode coalprefA coalprefB coalprefC coalprefD coalprefE coalprefF coalprefG coalprefH coalprefI (-99=.)

gen coalpref_complete = 1 if coalprefA!=. & coalprefB!=. & coalprefC!=. & coalprefD!=. & coalprefE!=. & coalprefF!=. & coalprefG!=. & coalprefH!=. & coalprefI!=.

gen coalpref = 3 if coalprefE >= coalprefA & coalprefE >= coalprefB & coalprefE >= coalprefC & coalprefE >= coalprefD & coalprefE >= coalprefF & coalprefE >= coalprefG & coalprefE >= coalprefH & coalprefE >= coalprefI & coalpref_complete == 1
replace coalpref = 2 if coalprefA == coalprefB & coalprefA == coalprefC & coalprefA == coalprefD & coalprefA == coalprefE & coalprefA == coalprefF & coalprefA == coalprefG  & coalprefA == coalprefH  & coalprefA == coalprefI & coalpref_complete == 1
replace coalpref = 1 if coalpref!=2 & coalpref!=3 & coalpref_complete == 1

replace coalpref = . if coalpref == 3 & coalprefE == coalprefA & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefE == coalprefB & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefE == coalprefC & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefE == coalprefD & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefE == coalprefF & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefE == coalprefG & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefE == coalprefH & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefE == coalprefI & coalpref_complete == 1

label define coalpref 1 "Loser coalition" 2 "No preference" 3 "Winner coalition"
label values coalpref coalpref

* Coalition preference strength

gen coalstrengthA = coalprefA if coalprefA >= coalprefB & coalprefA >= coalprefC & coalprefA >= coalprefD & coalprefA >= coalprefE & coalprefA >= coalprefF & coalprefA >= coalprefG & coalprefA >= coalprefH & coalprefA >= coalprefI & coalpref_complete == 1
gen coalstrengthB = coalprefB if coalprefB >= coalprefA & coalprefB >= coalprefC & coalprefB >= coalprefD & coalprefB >= coalprefE & coalprefB >= coalprefF & coalprefB >= coalprefG & coalprefB >= coalprefH & coalprefB >= coalprefI & coalpref_complete == 1
gen coalstrengthC = coalprefC if coalprefC >= coalprefA & coalprefC >= coalprefB & coalprefC >= coalprefD & coalprefC >= coalprefE & coalprefC >= coalprefF & coalprefC >= coalprefG & coalprefC >= coalprefH & coalprefC >= coalprefI & coalpref_complete == 1
gen coalstrengthD = coalprefD if coalprefD >= coalprefA & coalprefD >= coalprefB & coalprefD >= coalprefC & coalprefD >= coalprefE & coalprefD >= coalprefF & coalprefD >= coalprefG & coalprefD >= coalprefH & coalprefD >= coalprefI & coalpref_complete == 1
gen coalstrengthE = coalprefE if coalprefE >= coalprefA & coalprefE >= coalprefB & coalprefE >= coalprefC & coalprefE >= coalprefD & coalprefE >= coalprefF & coalprefE >= coalprefG & coalprefE >= coalprefH & coalprefE >= coalprefI & coalpref_complete == 1
gen coalstrengthF = coalprefF if coalprefF >= coalprefA & coalprefF >= coalprefB & coalprefF >= coalprefC & coalprefF >= coalprefD & coalprefF >= coalprefE & coalprefF >= coalprefG & coalprefF >= coalprefH & coalprefF >= coalprefI & coalpref_complete == 1
gen coalstrengthG = coalprefG if coalprefG >= coalprefA & coalprefG >= coalprefB & coalprefG >= coalprefC & coalprefG >= coalprefD & coalprefG >= coalprefE & coalprefG >= coalprefF & coalprefG >= coalprefH & coalprefG >= coalprefI & coalpref_complete == 1
gen coalstrengthH = coalprefH if coalprefH >= coalprefA & coalprefH >= coalprefB & coalprefH >= coalprefC & coalprefH >= coalprefD & coalprefH >= coalprefE & coalprefH >= coalprefF & coalprefH >= coalprefG & coalprefH >= coalprefI & coalpref_complete == 1
gen coalstrengthI = coalprefI if coalprefI >= coalprefA & coalprefI >= coalprefB & coalprefI >= coalprefC & coalprefI >= coalprefD & coalprefI >= coalprefE & coalprefI >= coalprefF & coalprefI >= coalprefH & coalprefI >= coalprefG & coalpref_complete == 1

gen coalstrength = max(coalstrengthA,coalstrengthB,coalstrengthC,coalstrengthD,coalstrengthE,coalstrengthF,coalstrengthG,coalstrengthH,coalstrengthI)

replace coalstrength = 300 if coalstrength == 8 | coalstrength == 9 | coalstrength == 10 | coalstrength == 11
replace coalstrength = 200 if coalstrength == 5 | coalstrength == 6 | coalstrength == 7
replace coalstrength = 100 if coalstrength == 1 | coalstrength == 2 | coalstrength == 3 | coalstrength == 4

replace coalstrength = 3 if coalstrength == 300
replace coalstrength = 2 if coalstrength == 200
replace coalstrength = 1 if coalstrength == 100

label define coalstrength 1 "Weak preference" 2 "Moderate preference" 3 "Strong preference"
label values coalstrength coalstrength

* Coalition preference scale

gen coalscale = .

replace coalscale = 1 if coalpref == 1 & coalstrength == 3
replace coalscale = 2 if coalpref == 1 & coalstrength == 2
replace coalscale = 3 if coalpref == 1 & coalstrength == 1
replace coalscale = 4 if coalpref == 2
replace coalscale = 5 if coalpref == 3 & coalstrength == 1
replace coalscale = 6 if coalpref == 3 & coalstrength == 2
replace coalscale = 7 if coalpref == 3 & coalstrength == 3

label define coalscale 1 "Strong loser preference" 2 "Moderate loser preference" 3 "Weak loser preference" 4 "No preference" 5 "Weak winner preference" 6 "Moderate winner preference" 7 "Strong winner preference" 
label values coalscale coalscale

* First/second vote and seats in parliament - Correct answer (second vote) = 1, Incorrect answer = 0

gen votes = q5

recode votes (1=0)
recode votes (2=1)
recode votes (3=0)

recode votes (-73=.)
recode votes (-98=0)
recode votes (-99=.)

* Political discussion

gen discussion = q89

recode discussion (-73=.)
recode discussion (-93=.)
recode discussion (-99=.)

gen discussion_3pts = 0 if discussion < 2 & discussion!=.
replace discussion_3pts = 1 if discussion >= 2 & discussion < 4 & discussion!=.
replace discussion_3pts = 2 if discussion >= 4 & discussion!=.

* Network size

gen size = q90

recode size (-72=.)
recode size (-73=.)
recode size (-93=.)
recode size (-97=.)
recode size (-99=.)

replace size = 0 if discussion == 0

gen size_3pts = size
replace size_3pts = 0 if size == 1
replace size_3pts = 1 if size == 2
replace size_3pts = 1 if size == 3
replace size_3pts = 1 if size == 4
replace size_3pts = 2 if size > 4 & size!=.

* Political disagreement

gen disagreement1 = q93
gen disagreement2 = q97

recode disagreement1 disagreement2 (-73=.)
recode disagreement1 disagreement2 (-93=.)
recode disagreement1 disagreement2 (-92=.)
recode disagreement1 disagreement2 (-97=.)
recode disagreement1 disagreement2 (-99=.)

replace disagreement1 = 4 - disagreement1
replace disagreement2 = 4 - disagreement2

replace disagreement1 = 0 if size == 0
replace disagreement2 = 0 if size < 2

gen disagreement = disagreement1 + disagreement2

gen disagreement1_3pts = disagreement1
gen disagreement2_3pts = disagreement2

replace disagreement1_3pts = 0 if disagreement1 == 1
replace disagreement1_3pts = 1 if disagreement1 == 2
replace disagreement1_3pts = 2 if disagreement1 == 3

replace disagreement2_3pts = 0 if disagreement2 == 1
replace disagreement2_3pts = 1 if disagreement2 == 2
replace disagreement2_3pts = 2 if disagreement2 == 3

egen disagreement_3pts = rowmax(disagreement1_3pts disagreement2_3pts)

* Main source of information

gen network_main = 1 if q64 == 6

replace network_main = 0 if q64!=6
replace network_main = . if q64 == -73
replace network_main = . if q64 == -93
replace network_main = . if q64 == -99


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

* Generate variable identifying incomplete answers

gen coalitionA = q58a
gen coalitionD = q58d
gen coalitionH = q58h
gen coalitionE = q58e
gen coalitionG = q58g
gen coalitionF = q58f
gen coalitionX = q58x

recode coalitionA coalitionD coalitionH coalitionE coalitionG coalitionF coalitionX (-73=.)
recode coalitionA coalitionD coalitionH coalitionE coalitionG coalitionF coalitionX (-93=.)
recode coalitionA coalitionD coalitionH coalitionE coalitionG coalitionF coalitionX (-98=.)
recode coalitionA coalitionD coalitionH coalitionE coalitionG coalitionF coalitionX (-99=.)

* Identify correct and incorrect forecasts

gen correct_whole_d = 1 if coalitionA == 0 & coalitionD == 1 & coalitionH == 0 & coalitionE == 1 & coalitionG == 0 & coalitionF == 1 & coalitionX == 0
replace correct_whole_d = 0 if correct_whole_d!=1
replace correct_whole_d = . if coalitionA == 0 & coalitionD == 0 & coalitionH == 0 & coalitionE == 0 & coalitionG == 0 & coalitionF == 0 & coalitionX == 0
replace correct_whole_d = 0 if q58a == -98 & q58d == -98 & q58h == -98 & q58e == -98 & q58g == -98 & q58f == -98 & q58x == -98


*********************************
** DISTRICT-LEVEL EXPECTATIONS ** 
*********************************

* Forecasts (1 = CDU/CSU, 4 = SPD, 5 = FDP, 6 = Green, 7 = Die Linke, 322 = AfD, 801 = other)

gen forecast_district1 = q59a
gen forecast_district2 = q59b

recode forecast_district1 forecast_district2 (-73=.)
recode forecast_district1 forecast_district2 (-93=.)
recode forecast_district1 forecast_district2 (-99=.)

egen forecast_district = rowmax(forecast_district1 forecast_district2)

* Identify correct forecasts

gen correct_district_d = 0 if forecast_district!=district_outcome & forecast_district!=.
replace correct_district_d = 1 if forecast_district == district_outcome & forecast_district!=.


**********
** SAVE **
**********

save "de2021_gles.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion disagreement size coalscale interest care_whole age i.male education time  
estimates table, star(.05 .01 .001)

margins, at(coalscale=1) atmeans predict(pr) // Average marginal effects
margins, at(coalscale=7) atmeans predict(pr) // Average marginal effects

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (district)

melogit correct_district_d discussion disagreement size pidscale_district interest age i.male education time enep || wknr: , or
estimates table, star(.05 .01 .001)

margins, at(pidscale_district=1) atmeans predict(pr) // Average marginal effects
margins, at(pidscale_district=7) atmeans predict(pr) // Average marginal effects

tab correct_district_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Coalition formed (DV)"
label variable correct_district_d "District winner (DV)"
label variable discussion "Discussion"
label variable disagreement "Disagreement"
label variable size "Network size"
label variable pidscale_whole "National PID"
label variable pidscale_district "District PID"
label variable coalscale "Coalition preference"
label variable interest "Interest"
label variable care_whole "Caring about outcome"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

quietly logistic correct_whole_d discussion disagreement size coalscale interest care_whole age i.male education time

estpost tabstat correct_whole_d discussion disagreement size coalscale interest care_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "de2021_gles_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2021 German federal election (GLES), national level") replace

eststo clear

quietly melogit correct_district_d discussion disagreement size pidscale_district interest age i.male education time enep i.reelected || wknr: , or

estpost tabstat correct_district_d discussion disagreement size pidscale_district interest age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "de2021_gles_summary_district.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2021 German federal election (GLES), district level") replace

eststo clear


*************************
** ADDITIONAL ANALYSES **
*************************

* Regression analysis (national)

logistic correct_whole_d i.network_main discussion disagreement size coalscale interest care_whole age i.male education time  
estimates table, star(.05 .01 .001)

* Regression analysis (district)

melogit correct_district_d i.network_main discussion disagreement size pidscale_district interest age i.male education time enep i.reelected || wknr: , or
estimates table, star(.05 .01 .001)

log close